# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: inkyu

from collections import namedtuple

FILL_ROW_FIELDS = [
    'time',
    'time_hr',
    'exchange',
    'product',
    'side',
    'price',
    'qty',
    'maker',
    'fee',
    'pos',
    'balance'
]
_FillRow = namedtuple('FillRowSingle', FILL_ROW_FIELDS)


class FillRow(_FillRow):
  @staticmethod
  def get_header():
    return 'header_fill_dump,%s' % ','.join(FILL_ROW_FIELDS)

  def to_log_string(self):
    return ('\n"FILL_DUMP",%d,"%s","%s","%s",'
            '%d,%f,%f,%d,%f,'
            '%f,%f' % (self.time,
                       self.time_hr,
                       self.exchange,
                       self.product,
                       self.side,
                       self.price,
                       self.qty,
                       self.maker,
                       self.fee,
                       self.pos,
                       self.balance))


FEATURE_ROW_FIELDS = [
    'time',
    'time_hr',
    'ask0_1',
    'askt_1',
    'bid0_1',
    'bidt_1',
    'ask0_2',
    'askt_2',
    'bid0_2',
    'bidt_2',
    'ask_basis_ma',
    'bid_basis_ma'
]
_FeatureRow = namedtuple('FeatureRow', FEATURE_ROW_FIELDS)


class FeatureRow(_FeatureRow):
  @staticmethod
  def get_header():
    return 'header_feature_dump,%s' % ','.join(FEATURE_ROW_FIELDS)

  def to_csv(self):
    return ('"FEATURE_DUMP",%d,"%s",'
            '%f,%f,%f,%f,%f,%f,%f,%f,%f,%f' % (self.time,
                                               self.time_hr,
                                               self.ask0_1,
                                               self.askt_1,
                                               self.bid0_1,
                                               self.bidt_1,
                                               self.ask0_2,
                                               self.askt_2,
                                               self.bid0_2,
                                               self.bidt_2,
                                               self.ask_basis_ma,
                                               self.bid_basis_ma))

  def to_log_string(self):
    return '\n' + self.to_csv()
